version: '3'
services:
  etcd:
    image: "bitnami/etcd:latest"
    deploy:
      restart_policy:
        condition: any
        delay: 30s
    environment:
      - ALLOW_NONE_AUTHENTICATION=yes
    ports:
      - "{{ etcd_port }}:{{ etcd_port }}"

  broker:
    image: "overmoon"
    deploy:
      restart_policy:
        condition: any
        delay: 30s
    volumes:
      - ${PWD}/examples/overmoon/config.yaml:/overmoon/config.yaml
    command: overmoon
    ports:
    - "{{ broker_port }}:{{ broker_port }}"

{% filter indent(width=2) %}
{% for coordinator_id in range(coordinator_num) %}
coordinator{{ coordinator_id }}:
  image: "undermoon"
  deploy:
    restart_policy:
      condition: any
      delay: 30s
  volumes:
  - ${PWD}/examples/target_volume:/undermoon/target
  command: /undermoon/target/debug/coordinator
  environment:
  - RUST_LOG=undermoon=debug,coordinator=debug
  - RUST_BACKTRACE=full
  - UNDERMOON_BROKER_ADDRESS={{ broker_address }}
  - UNDERMOON_REPORTER_ID=coordinator{{ coordinator_id }}
{% endfor %}
{% endfilter %}

{% filter indent(width=2) %}
{% for redis_port in redis_ports %}
redis{{ redis_port }}:
  image: "redis"
  deploy:
    restart_policy:
      condition: any
      delay: 30s
  command: redis-server --port {{ redis_port }} --slave-announce-ip redis{{ redis_port }} --slave-announce-port {{ redis_port }} --maxmemory {{ redis_maxmemory }}
  ports:
  - "{{ redis_port }}:{{ redis_port }}"
{% endfor %}
{% endfilter %}

{% filter indent(width=2) %}
{% for proxy_port in server_proxy_ports %}
server_proxy{{ proxy_port }}:
  image: "undermoon"
  deploy:
    restart_policy:
      condition: any
      delay: 30s
  volumes:
  - ${PWD}/examples/target_volume:/undermoon/target
  command: /undermoon/target/debug/server_proxy
  ports:
  - "{{ proxy_port }}:{{ proxy_port }}"
  environment:
  - RUST_LOG=undermoon=debug,server_proxy=debug
  - RUST_BACKTRACE=full
  - UNDERMOON_ADDRESS=0.0.0.0:{{ proxy_port }}
  - UNDERMOON_ANNOUNCE_ADDRESS=server_proxy{{ proxy_port }}:{{ proxy_port }}
  - UNDERMOON_AUTO_SELECT_CLUSTER=true
  - UNDERMOON_SLOWLOG_LEN=1024
  - UNDERMOON_SLOWLOG_LOG_SLOWER_THAN=50000
  - UNDERMOON_THREAD_NUMBER=1
  - UNDERMOON_SESSION_CHANNEL_SIZE=4096
  - UNDERMOON_BACKEND_CHANNEL_SIZE=4096
  - UNDERMOON_BACKEND_CONN_NUM=4
{% endfor %}
{% endfilter %}

{% filter indent(width=2) %}
{% for name, cmd in pumba_commands.items() %}
pumba_{{ name }}:
  image: "gaiaadm/pumba"
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  command: {{ cmd }}
{% endfor %}
{% endfilter %}
